home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / biz / patch / fixobj.lha / FixObj.e < prev   
Text File  |  1993-03-03  |  2KB  |  65 lines

  1. /* FixObj.e    Replaces $0d characters out of Pixel3D Pro
  2.            Wavefront files with $20
  3.            Also adds 'g' lines which set up grouping data
  4.                                   */
  5.  
  6. ENUM ER_NONE, ER_FILE, ER_MEM, ER_USAGE,ER_BRK, ER_OUT
  7.  
  8. DEF flen, mem:PTR TO CHAR,wmem:PTR TO CHAR, pos:PTR TO CHAR,wpos:PTR TO CHAR
  9. DEF handle=NIL
  10.  
  11. PROC main()
  12.    WriteF('FixObj : Fixes Pixel3DPro-generated Wavefront files\n')
  13.    WriteF('(c) 1993 Danimal\n\n')
  14.    IF StrCmp(arg,'',1) OR StrCmp(arg,'?',2) THEN error(ER_USAGE)
  15.    flen:=FileLength(arg)
  16.    handle:=Open(arg,OLDFILE)
  17.    IF (flen<1) OR (handle=NIL) THEN error(ER_FILE)
  18.    mem:=New(flen+4); wmem:= New(flen+10)
  19.    IF (mem=NIL OR wmem=NIL) THEN error(ER_MEM)
  20.    IF Read(handle,mem,flen)<>flen THEN error(ER_FILE)
  21.    Close(handle); handle:=NIL
  22.    WriteF('Now fixing "\s"\n',arg)
  23.    fix()
  24.    handle:=Open(arg,NEWFILE)
  25.    IF handle=NIL THEN error(ER_OUT)
  26.    WriteF('Writing "\s".\n',arg)
  27.    IF Write(handle,wmem,flen)<>flen THEN error(ER_OUT)
  28.    error(ER_NONE)
  29. ENDPROC
  30.  
  31. PROC error(nr)
  32.    IF handle THEN Close(handle)
  33.    SELECT nr
  34.       CASE ER_NONE;   WriteF('Done.\n')
  35.       CASE ER_FILE;   WriteF('Could not read file "\s"\n',arg)
  36.       CASE ER_MEM;    WriteF('No memory for loading file\n')
  37.       CASE ER_USAGE;  WriteF('USAGE: Wavefix <file>\n')
  38.       CASE ER_BRK;    WriteF('**User Break**\n')
  39.       CASE ER_OUT;    WriteF('Could not write file "\s"\n',arg)
  40.    ENDSELECT
  41.    CleanUp(0)
  42. ENDPROC
  43.  
  44. PROC fix()
  45. /*     This procedure makes the actual corrections to the file   */
  46.  
  47. DEF counter=0,firstf=NIL
  48.    pos:=mem; wpos:=wmem
  49.    wpos[]++:=$67; wpos[]++:=$0a
  50.    flen:=flen+2
  51.    REPEAT
  52.       IF CtrlC() THEN error(ER_BRK)
  53.       IF (pos[]=$66 AND (firstf=NIL))
  54.      wpos[]++:=$67; wpos[]++:=$0a
  55.      firstf:=wpos
  56.      flen:=flen+2
  57.       ENDIF
  58.       IF pos[]=$0D THEN wpos[]:=$20
  59.       IF pos[]=$0a THEN counter++
  60.       wpos[]++:=pos[]++
  61.       IF Mod(counter,50)=0 THEN WriteF('\bLine: \d   ',counter)
  62.    UNTIL (pos-mem)>=flen
  63.    WriteF('\n')
  64. ENDPROC
  65.